class Fence extends egret.Sprite {
	private _r: number = 5;
	private _y2: number = 0;
	private _y1: number = 0;
	private _x1: number = 0;
	private _x2: number = 0;
	private _sync: Sync = null;

	public constructor(x1: number, y1: number, x2: number, y2: number) {
		super();

		this._x1 = x1;
		this._y1 = y1;
		this._x2 = x2;
		this._y2 = y2;
		this._sync = new Sync(0.2);
		this.draw();
		this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
	}

	public get y2(): number {
		return (this._y2);
	}

	public get x2(): number {
		return (this._x2);
	}

	public destruct() {
		this.graphics.clear();
	}

	public set x1(x: number) {
		this._x1 = x;
		this.draw();
	}

	private onEnterFrame(event: egret.Event) {
		this._sync.tick();
		this.draw();
	}

	private draw() {
		var g: egret.Graphics = this.graphics;
		var dx: number = (this._x2 - this._x1);
		var dy: number = (this._y2 - this._y1);
		var a: number = Math.atan2(dy, dx);
		var r: number = this._r;
		var a90: number = (Math.PI / 2);
		var a180: number = Math.PI;
		var delta: number = ((Math.sin(this._sync.phase) * 5) + 2);
		var delta2: number = (Math.sin((this._sync.phase + a180)) + 2);
		g.clear();
		g.lineStyle(2, GUI.OUTLINE_COLOR);
		g.beginFill(5592371, 1);
		g.moveTo(((Math.cos((a + a90)) * r) + this._x1), ((Math.sin((a + a90)) * r) + this._y1));
		g.curveTo((((Math.cos((a + a180)) * r) * delta2) + this._x1), (((Math.sin((a + a180)) * r) * delta2) + this._y1), ((Math.cos((a - a90)) * r) + this._x1), ((Math.sin((a - a90)) * r) + this._y1));
		g.curveTo((((Math.cos((a - a90)) * delta) + (dx / 2)) + this._x1), (((Math.sin((a - a90)) * delta) + (dy / 2)) + this._y1), ((Math.cos((a - a90)) * r) + this._x2), ((Math.sin((a - a90)) * r) + this._y2));
		g.curveTo((((Math.cos(a) * r) * delta2) + this._x2), (((Math.sin(a) * r) * delta2) + this._y2), ((Math.cos((a + a90)) * r) + this._x2), ((Math.sin((a + a90)) * r) + this._y2));
		g.curveTo((((Math.cos((a + a90)) * delta) + (dx / 2)) + this._x1), (((Math.sin((a + a90)) * delta) + (dy / 2)) + this._y1), ((Math.cos((a + a90)) * r) + this._x1), ((Math.sin((a + a90)) * r) + this._y1));
		g.endFill();
	}

	public set y1(y: number) {
		this._y1 = y;
		this.draw();
	}

	public set y2(y: number) {
		this._y2 = y;
		this.draw();
	}

	public get x1(): number {
		return (this._x1);
	}

	public set x2(x: number) {
		this._x2 = x;
		this.draw();
	}

	public get y1(): number {
		return (this._y1);
	}

}


